package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.hencoder.hencoderpracticedraw1.R;

public class Practice8DrawArcView extends View {

    private Paint mPaint;

    public Practice8DrawArcView(Context context) {
        super(context);
    }

    public Practice8DrawArcView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
    }

    public Practice8DrawArcView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        练习内容：使用 canvas.drawArc() 方法画弧形和扇形
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            canvas.drawArc(getResources().getDimensionPixelOffset(R.dimen.x200),
                    getResources().getDimensionPixelOffset(R.dimen.x100),
                    getResources().getDimensionPixelOffset(R.dimen.x450),
                    getResources().getDimensionPixelOffset(R.dimen.x300),
                    -getResources().getDimensionPixelOffset(R.dimen.x110),
                    getResources().getDimensionPixelOffset(R.dimen.x100), true, mPaint);
            canvas.drawArc(getResources().getDimensionPixelOffset(R.dimen.x200),
                    getResources().getDimensionPixelOffset(R.dimen.x100),
                    getResources().getDimensionPixelOffset(R.dimen.x450),
                    getResources().getDimensionPixelOffset(R.dimen.x300),
                    getResources().getDimensionPixelOffset(R.dimen.x20),
                    getResources().getDimensionPixelOffset(R.dimen.x140), false, mPaint);
            mPaint.setStyle(Paint.Style.STROKE);
            canvas.drawArc(getResources().getDimensionPixelOffset(R.dimen.x200),
                    getResources().getDimensionPixelOffset(R.dimen.x100),
                    getResources().getDimensionPixelOffset(R.dimen.x400),
                    getResources().getDimensionPixelOffset(R.dimen.x300),
                    getResources().getDimensionPixelOffset(R.dimen.x180),
                    getResources().getDimensionPixelOffset(R.dimen.x60), false, mPaint);
        }

    }
}
